package com.zlzxm.zutil.ui.widget.recyclerviewutil;

import android.graphics.Rect;
import android.view.View;

import com.zlzxm.zutil.ui.viewhelp.ZViewHelp;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

/**
 * Created by zlz
 * on  2019/6/26
 */
public class RightSpace extends RecyclerView.ItemDecoration {

    private final int rightSpace ;

    public RightSpace(int rightSpace) {

        this.rightSpace = rightSpace;
    }

    @Override
    public void getItemOffsets(@NonNull Rect outRect, @NonNull View view, @NonNull RecyclerView parent, @NonNull RecyclerView.State state) {

        if(parent.getAdapter() != null) {

            if (parent.getChildAdapterPosition(view) != parent.getAdapter().getItemCount() - 1) {

                outRect.right = ZViewHelp.dpTopx(parent.getContext(), rightSpace);

            }else {

                outRect.right = 0;
            }
        }
    }


}
